package com.freedom.mediaplayer.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.freedom.mediaplayer.R;
import com.freedom.mediaplayer.adapter.MusicListAdapter;
import com.freedom.mediaplayer.app.AppConstant;
import com.freedom.mediaplayer.until.DataUtil;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;



public class SongMenu extends BaseFragment implements OnItemClickListener {
	public static final String UPDATE_DATE = "com.freedom.action.UPDATE_DATE"; // 更新动作
	@ViewInject(R.id.songmenu)
	private ListView listView;
	private MusicListAdapter adapter;
	//private List<Music> list; 
	
	@Override
	public View initView(LayoutInflater inflater) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment01, null);
		ViewUtils.inject(this, view);
		return view;
	}

	@Override
	public void initData(Bundle savedInstanceState) {
		//list = DataUtil.list;
		adapter = new MusicListAdapter(ct, DataUtil.list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		if (DataUtil.list != null) {
			// curPosition = arg2;
			Intent intent = new Intent();
			intent.setAction("com.freedom.media.MUSIC_SERVICE");
			intent.putExtra("url", DataUtil.list.get(arg2).getUrl());
			intent.putExtra("MSG", AppConstant.PlayerMsg.PLAY_MSG);
			// intent.putExtra("curPosition", curPosition);
			ct.startService(intent);
			DataUtil.curPosition = arg2;
			DataUtil.isPlaying = true;
		}
	}
}
